
package com.tianbo.elfii.client.common;

import java.io.*;
import java.util.*;
import java.net.*;
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.image.*;
import javax.imageio.*;

import sun.audio.AudioPlayer;
import sun.audio.AudioStream;


/**  <pre>
     <b>类功能描述：</b>
     工具集.
     </pre>
     @version 1.0.1
     @author 高伟 
*/

public class ElfiiCommonUtil  {

    public static JPanel createTopPanelBlank(String title) {
        final String title2=title;
        JPanel p = new JPanel() {
                public void paintComponent(Graphics g) {
                    super.paintComponent(g);

                    File f=null;
                    BufferedImage bgImage=null;
                    try {
                        f=new File("resource-common/images/gw/gw_bg_01.png");
                        bgImage=ImageIO.read(f);
                    } catch(Exception e) {System.out.print(e+"  "+f);}
                    Graphics2D g2 = (Graphics2D) g ;
                    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 
                    g2.drawImage(bgImage,null,0,0);
                    g2.setFont(ElfiiCommonConstant.Window_Title_Font);
                    int strLen=g.getFontMetrics().stringWidth(title2);
                    g2.drawString(title2,512-strLen/2,60);
                }
                public Dimension getPreferredSize() {
                    return (new Dimension(1024,100));
                }
            };
        return p;
    }

    public static JPanel createTopPanel(String title,JButton backButton,JButton homeButton) {
        final String title2=title;
        JPanel p = new JPanel() {
                public void paintComponent(Graphics g) {
                    super.paintComponent(g);

                    File f=null;
                    BufferedImage bgImage=null;
                    BufferedImage btnBackImage=null;
                    BufferedImage btnHomeImage=null;
                    try {
                        f=new File("resource-common/images/gw/gw_bg_01.png");
                        bgImage=ImageIO.read(f);
                        f=new File("resource-common/images/btn-back.png");
                        btnBackImage=ImageIO.read(f);
                        f=new File("resource-common/images/btn-home.png");
                        btnHomeImage=ImageIO.read(f);
                    } catch(Exception e) {System.out.print(e+"  "+f);}
                    Graphics2D g2 = (Graphics2D) g ;
                    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 
                    g2.drawImage(bgImage,null,0,0);
                    g2.setFont(ElfiiCommonConstant.Window_Title_Font);
                    int strLen=g.getFontMetrics().stringWidth(title2);
                    g2.drawString(title2,512-strLen/2,60);
                }
                public Dimension getPreferredSize() {
                    return (new Dimension(1024,100));
                }
            };

        p.setLayout(null);

        ImageIcon backIcon = new ImageIcon("resource-common/images/btn-back.png","");
        if (backButton==null)
            backButton=new JButton();
        backButton.setBackground(Color.white);
        backButton.setBorderPainted(false);
        backButton.setFocusPainted(false);
        backButton.setIcon(backIcon);
        backButton.setModel(new DefaultButtonModel() {
                public boolean isPressed(){
                    return false; 
                }
            }
            ) ;
        p.add(backButton);
        backButton.setBounds(ElfiiCommonConstant.Go_Back_Button_X,ElfiiCommonConstant.Go_Back_Button_Y,51,65);
        
        p.add(homeButton);
        homeButton.setBounds(ElfiiCommonConstant.Go_Home_Button_X,ElfiiCommonConstant.Go_Home_Button_Y,51,65);

        return p;
    }

    public static JPanel createBottomPanelBlank() {
        JPanel panel = new JPanel() {
                public void paintComponent(Graphics g) {
                    super.paintComponent(g);

                    File f=null;
                    BufferedImage bgImage=null;
                    try {
                        f=new File("resource-common/images/gw/gw_bg_02.png");
                        bgImage=ImageIO.read(f);
                    } catch(Exception e) {System.out.print(e+"  "+f);}
                    Graphics2D g2 = (Graphics2D) g ;
                    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 
                    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 
                    g2.drawImage(bgImage,null,0,0);
                }
                public Dimension getPreferredSize() {
                    return (new Dimension(1024,100));
                }
            };
        return panel;
    }

    public static JPanel createBottomPanelLevelSelect(JButton okButton) {
        ImageIcon okIcon = new ImageIcon("resource-common/images/confirm.png","");
        okButton.setBackground(Color.white);
        okButton.setBorderPainted(false);
        okButton.setFocusPainted(false);
        okButton.setIcon(okIcon);
        okButton.setModel(new DefaultButtonModel() {
                public boolean isPressed(){
                    return false; 
                }
            }
            ) ;
        JPanel panel = createBottomPanelBlank();
        panel.setLayout(null);
        panel.add(okButton);
        okButton.setBounds(480,25,58,73);
        return panel;
    }

    public static JPanel createBottomPanelTrain(JButton okButton,JButton repeatButton) {
        JPanel panel = createBottomPanelBlank();
        panel.setLayout(null);
        if (okButton!=null){
            ImageIcon okIcon = new ImageIcon("resource-common/images/confirm.png","");
            okButton.setBackground(Color.white);
            okButton.setBorderPainted(false);
            okButton.setFocusPainted(false);
            okButton.setIcon(okIcon);
            okButton.setModel(new DefaultButtonModel() {
                    public boolean isPressed(){
                        return false; 
                    }
                }
                ) ;
            panel.add(okButton);
            okButton.setBounds(370,25,58,73);
        }
        if (repeatButton!=null){
            ImageIcon repeatIcon = new ImageIcon("resource-common/images/replayButton.png","");
            repeatButton.setBackground(Color.white);
            repeatButton.setBorderPainted(false);
            repeatButton.setFocusPainted(false);
            repeatButton.setIcon(repeatIcon);
            repeatButton.setModel(new DefaultButtonModel() {
                    public boolean isPressed(){
                        return false; 
                    }
                }
                ) ;
            panel.add(repeatButton);
            repeatButton.setBounds(570,25,58,73);
        }

        return panel;
    }

    public static JPanel createBottomPanelMenu(JButton saveDataButton,JButton noDataButton) {
        JPanel panel = createBottomPanelBlank();
        panel.setLayout(null);
        if (saveDataButton!=null){
            ImageIcon saveDataIcon = new ImageIcon("resource-common/images/testPattern.png","");
            saveDataButton.setBackground(Color.white);
            saveDataButton.setBorderPainted(false);
            saveDataButton.setFocusPainted(false);
            saveDataButton.setIcon(saveDataIcon);
            saveDataButton.setModel(new DefaultButtonModel() {
                    public boolean isPressed(){
                        return false; 
                    }
                }
                ) ;
            panel.add(saveDataButton);
            saveDataButton.setBounds(370,25,58,73);
        }
        if (noDataButton!=null){
            ImageIcon noDataIcon = new ImageIcon("resource-common/images/practicePattern.png","");
            noDataButton.setBackground(Color.white);
            noDataButton.setBorderPainted(false);
            noDataButton.setFocusPainted(false);
            noDataButton.setIcon(noDataIcon);
            noDataButton.setModel(new DefaultButtonModel() {
                    public boolean isPressed(){
                        return false; 
                    }
                }
                ) ;
            panel.add(noDataButton);
            noDataButton.setBounds(570,25,58,73);
        }

        return panel;
    }

    public static JPanel createBottomPanelTwoButton(JButton firstButton,JButton secondButton) {
        JPanel panel = createBottomPanelBlank();
        panel.setLayout(null);
        if (firstButton!=null){
            firstButton.setBackground(Color.white);
            firstButton.setBorderPainted(false);
            firstButton.setFocusPainted(false);
            firstButton.setModel(new DefaultButtonModel() {
                    public boolean isPressed(){
                        return false; 
                    }
                }
                ) ;
            panel.add(firstButton);
            firstButton.setBounds(370,25,73,73);
        }
        if (secondButton!=null){
            secondButton.setBackground(Color.white);
            secondButton.setBorderPainted(false);
            secondButton.setFocusPainted(false);
            secondButton.setModel(new DefaultButtonModel() {
                    public boolean isPressed(){
                        return false; 
                    }
                }
                ) ;
            panel.add(secondButton);
            secondButton.setBounds(570,25,73,73);
        }

        return panel;
    }

    public static String getTrainningCategory(String trainningTitle) {

        String trainningCategory=null;

        if (trainningTitle.startsWith("A"))
            trainningCategory="视觉触觉综合训练1";
        if (trainningTitle.startsWith("B"))
            trainningCategory="视觉触觉综合训练2";
        if (trainningTitle.startsWith("C"))
            trainningCategory="听觉触觉综合训练";
        if (trainningTitle.startsWith("D"))
            trainningCategory="视觉听觉触觉综合训练";
        if (trainningTitle.startsWith("E"))
            trainningCategory="听觉辨识训练";
        if (trainningTitle.startsWith("F"))
            trainningCategory="听觉系统反应训练";
        if (trainningTitle.startsWith("G"))
            trainningCategory="听觉系统记忆训练";
        if (trainningTitle.startsWith("H"))
            trainningCategory="形状辨识强度训练";
        if (trainningTitle.startsWith("I"))
            trainningCategory="颜色辨识强度训练";
        if (trainningTitle.startsWith("J"))
            trainningCategory="符号辨识强度训练";
        if (trainningTitle.startsWith("K"))
            trainningCategory="空间位置记忆训练";
        if (trainningTitle.startsWith("L"))
            trainningCategory="手眼协调训练";
        if (trainningTitle.startsWith("M"))
            trainningCategory="手指稳定性训练";
        if (trainningTitle.startsWith("N"))
            trainningCategory="双手协调训练";
        return trainningCategory ;
    }

    public static String space(int spaceLength) {
        String kkstr="";
        for (int i=0; i<spaceLength; i++)
            kkstr=kkstr+" ";
        return kkstr ;
    }

    public static String getLocalCurrentDate(String divStr) {
        java.util.Date date = new java.util.Date() ;
        String[] month = {"Jan01","Feb02","Mar03","Apr04","May05","Jun06","Jul07","Aug08","Sep09","Oct10","Nov11","Dec12"} ;
        String kkstr=date.toString().trim();
        String yearStr = kkstr.substring(kkstr.length()-4,kkstr.length());
        String dayStr = kkstr.substring(8,10);
        String monthStr = kkstr.substring(4,7) ;
        for (int i=0; i<12; i++) {
            if (month[i].startsWith(monthStr))
                monthStr=month[i].substring(3,5);
        }
        String dateString = yearStr+divStr+monthStr+divStr+dayStr ;
        return  dateString ;
    }

    public static String getLocalCurrentTime(String divStr) {
        java.util.Date date = new java.util.Date() ;
        String kkstr=date.toString();
        kkstr=kkstr.substring(11,19);
        kkstr=kkstr.replaceAll(":",divStr);
        return  kkstr ;
    }

    public static void drawResultY100(Graphics g,java.util.Vector exerciseTopics,String infoStr){
        drawGraphicResult(100,g,exerciseTopics,null);
    }
    public static void drawResult(Graphics g,java.util.Vector exerciseTopics,String infoStr){
        drawGraphicResult(0,g,exerciseTopics,null);
    }

    public static void drawGraphicResult(int startY0,Graphics g,java.util.Vector<ElfiiCommonTypeTopic> exerciseTopics,ElfiiCommonHistoryTypeInfo historyInfo){

        Graphics2D g2 = (Graphics2D) g ;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 

        //-此处用 p1,p2,p3 代表 前期，中期，后期 三个部分，即part One,two,tree。
        int p1Number=0;
        int p2Number=0;
        int p3Number=0;
        int pNumberMax=0;
        int size=0;
        ElfiiCommonTypeTopic tmpTopic;
        tmpTopic=exerciseTopics.get(0);
        if (exerciseTopics.get(0).section==0) {
            int k=-1;
            size=exerciseTopics.size();
            while(k<size) {
                k++;
                if (k<size)
                    p1Number++;
                k++;
                if (k<size)
                    p2Number++;
                k++;
                if (k<size)
                    p3Number++;
            }
            //System.out.println("=====B size:"+size+",p1:"+p1Number+",p2:"+p2Number+",p3:"+p3Number);
            for (int i=0; i<p1Number; i++)
                exerciseTopics.get(i).section=ElfiiCommonConstant.Section_1;;
            for (int i=p1Number; i<p1Number+p2Number; i++)
                exerciseTopics.get(i).section=ElfiiCommonConstant.Section_2;;
            for (int i=p1Number+p2Number; i<p1Number+p2Number+p3Number; i++)
                exerciseTopics.get(i).section=ElfiiCommonConstant.Section_3;;
        }else{
            for (int i=0; i<exerciseTopics.size(); i++){
                if (exerciseTopics.get(i).section==ElfiiCommonConstant.Section_1) 
                    p1Number++;
                if (exerciseTopics.get(i).section==ElfiiCommonConstant.Section_2) 
                    p2Number++;
                if (exerciseTopics.get(i).section==ElfiiCommonConstant.Section_3) 
                    p3Number++;
            }
        }

        int maxNumber=p1Number;
        if (p2Number>maxNumber)
            maxNumber=p2Number;
        if (p3Number>maxNumber)
            maxNumber=p3Number;

        int roundWidth=ElfiiCommonConstant.Result_Round_Rect_Width;
        int roundSpace=ElfiiCommonConstant.Result_Round_Rect_Space;
        if (maxNumber>=13){
            //double d=size*1.000;
            int a=(int)Math.round(maxNumber*1.000-13+0.17);
            //System.out.println("======BBB"+a);
            roundWidth=roundWidth-a*3;
        }

        int maxRoundRectWidth=100+maxNumber*(roundWidth+roundSpace);
        int baseX0=512-maxRoundRectWidth/2-50;
        int lineSpace=140;
        int baseY0=startY0+90;

        if (historyInfo!=null){
            baseX0=512-maxRoundRectWidth/2-120;
            baseY0=startY0+100;
            lineSpace=120;
        }
        if (baseX0>160)
            baseX0=160;

        String p1Title="前期";
        int p1TitleX0=baseX0;
        int p1TitleY0=baseY0+55;
        int p1RoundRectX0=baseX0+80;
        int p1RoundRectY0=baseY0;
        int p1CurrentResultsX0=baseX0+100+p1Number*(roundWidth+roundSpace);
        int p1CurrentResultsY0=p1TitleY0;
        int p1AvgResultsX0=p1CurrentResultsX0+120;
        int p1AvgResultsY0=p1TitleY0;
        int p1RoundRectWidth=p1Number*(roundWidth+roundSpace)+5;

        String p2Title="中期";
        int p2TitleX0=baseX0;
        int p2TitleY0=baseY0+55+lineSpace;
        int p2RoundRectX0=baseX0+80;
        int p2RoundRectY0=baseY0+lineSpace;
        int p2CurrentResultsX0=baseX0+100+p2Number*(roundWidth+roundSpace);
        int p2CurrentResultsY0=p2TitleY0;
        int p2AvgResultsX0=p2CurrentResultsX0+120;
        int p2AvgResultsY0=p2TitleY0;
        int p2RoundRectWidth=p2Number*(roundWidth+roundSpace)+5;

        String p3Title="后期";
        int p3TitleX0=baseX0;
        int p3TitleY0=baseY0+55+lineSpace*2;
        int p3RoundRectX0=baseX0+80;
        int p3RoundRectY0=baseY0+lineSpace*2;
        int p3CurrentResultsX0=baseX0+100+p3Number*(roundWidth+roundSpace);
        int p3CurrentResultsY0=p3TitleY0;
        int p3AvgResultsX0=p3CurrentResultsX0+120;
        int p3AvgResultsY0=p3TitleY0;
        int p3RoundRectWidth=p3Number*(roundWidth+roundSpace)+5;

        String p4Title="综合";
        int p4TitleX0=baseX0;
        int p4TitleY0=baseY0+35+lineSpace*3;
        int p4CurrentResultsX0=0;
        int p4CurrentResultsY0=p4TitleY0;;
        int p4AvgResultsX0=p4CurrentResultsX0+120;
        int p4AvgResultsY0=p4TitleY0;;

        if (historyInfo!=null){
            int a=p1CurrentResultsX0;
            if (a<p2CurrentResultsX0)
                a=p2CurrentResultsX0;
            if (a<p3CurrentResultsX0)
                a=p3CurrentResultsX0;
            if (a<612)
                a=612;

            p1CurrentResultsX0=a;
            p2CurrentResultsX0=a;
            p3CurrentResultsX0=a;
            p4CurrentResultsX0=a;
            p1AvgResultsX0=p1CurrentResultsX0+160;
            p2AvgResultsX0=p2CurrentResultsX0+160;
            p3AvgResultsX0=p3CurrentResultsX0+160;
            p4AvgResultsX0=p4CurrentResultsX0+160;
        }

        String str;
        int topicIndex=-1;  //必须是-1
        int okNumber,wrongNumber=0;
        g2.setColor(Color.black);
        g2.fillRect(0,startY0,1024,568);

        okNumber=0;                
        wrongNumber=0;                
        g2.setColor(Color.white);
        g2.setStroke(new BasicStroke(4.0f));
        g2.drawRoundRect(p1RoundRectX0,p1RoundRectY0,p1RoundRectWidth,90,40,40);
        for (int i=0; i<p1Number; i++){
            topicIndex++;
            tmpTopic=exerciseTopics.elementAt(topicIndex);
            if (tmpTopic.actionResult==ElfiiCommonConstant.React_Ok){
                g2.setColor(ElfiiCommonConstant.Elfii_Blue);
                okNumber++;
            }else{
                g2.setColor(ElfiiCommonConstant.Elfii_Orange);
                wrongNumber++;
            }
            g2.fillRoundRect(p1RoundRectX0+5+i*(roundWidth+roundSpace),p1RoundRectY0+5,roundWidth,80,40,40);
        }                
        g2.setColor(Color.white);
        g2.setFont(ElfiiCommonConstant.Trainning_Result_Font);
        g2.drawString(p1Title,p1TitleX0,p1TitleY0);
        if (historyInfo==null)
            g2.drawString(""+okNumber+"/"+(okNumber+wrongNumber),p1CurrentResultsX0,p1CurrentResultsY0);
        if (historyInfo!=null){
            g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,26));
            if (okNumber==0){
                g2.drawString("0.0%",p1CurrentResultsX0,p1CurrentResultsY0);
            }else{
                double d=100.0*okNumber/(okNumber+wrongNumber);
                str=""+(d+0.05);
                if (str.length()-str.indexOf(".")>1)
                    str=str.substring(0,str.indexOf(".")+2);
                g2.drawString(str+"%",p1CurrentResultsX0,p1CurrentResultsY0);
            }
        }

        okNumber=0;                
        wrongNumber=0;                
        g2.setColor(Color.white);
        g2.setStroke(new BasicStroke(4.0f));
        g2.drawRoundRect(p2RoundRectX0,p2RoundRectY0,p2RoundRectWidth,90,40,40);
        for (int i=0; i<p2Number; i++){
            topicIndex++;
            tmpTopic=exerciseTopics.elementAt(topicIndex);
            if (tmpTopic.actionResult==ElfiiCommonConstant.React_Ok){
                g2.setColor(ElfiiCommonConstant.Elfii_Blue);
                okNumber++;
            }else{
                g2.setColor(ElfiiCommonConstant.Elfii_Orange);
                wrongNumber++;
            }
            g2.fillRoundRect(p2RoundRectX0+5+i*(roundWidth+roundSpace),p2RoundRectY0+5,roundWidth,80,40,40);
        }                
        g2.setColor(Color.white);
        g2.setFont(ElfiiCommonConstant.Trainning_Result_Font);
        g2.drawString(p2Title,p2TitleX0,p2TitleY0);
        if (historyInfo==null)
            g2.drawString(""+okNumber+"/"+(okNumber+wrongNumber),p2CurrentResultsX0,p2CurrentResultsY0);
        if (historyInfo!=null){
            g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,26));
            if (okNumber==0){
                g2.drawString("0.0%",p2CurrentResultsX0,p2CurrentResultsY0);
            }else{
                double d=100.0*okNumber/(okNumber+wrongNumber);
                str=""+(d+0.05);
                if (str.length()-str.indexOf(".")>1)
                    str=str.substring(0,str.indexOf(".")+2);
                g2.drawString(str+"%",p2CurrentResultsX0,p2CurrentResultsY0);
            }
        }

        okNumber=0;                
        wrongNumber=0;                
        g2.setColor(Color.white);
        g2.setStroke(new BasicStroke(4.0f));
        g2.drawRoundRect(p3RoundRectX0,p3RoundRectY0,p3RoundRectWidth,90,40,40);
        for (int i=0; i<p3Number; i++){
            topicIndex++;
            tmpTopic=exerciseTopics.elementAt(topicIndex);
            if (tmpTopic.actionResult==ElfiiCommonConstant.React_Ok){
                g2.setColor(ElfiiCommonConstant.Elfii_Blue);
                okNumber++;
            }else{
                g2.setColor(ElfiiCommonConstant.Elfii_Orange);
                wrongNumber++;
            }
            g2.fillRoundRect(p3RoundRectX0+5+i*(roundWidth+roundSpace),p3RoundRectY0+5,roundWidth,80,40,40);
        }                
        g2.setColor(Color.white);
        g2.setFont(ElfiiCommonConstant.Trainning_Result_Font);
        g2.drawString(p3Title,p3TitleX0,p3TitleY0);
        if (historyInfo==null)
            g2.drawString(""+okNumber+"/"+(okNumber+wrongNumber),p3CurrentResultsX0,p3CurrentResultsY0);
        if (historyInfo!=null){
            g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,26));
            if (okNumber==0){
                g2.drawString("0.0%",p3CurrentResultsX0,p3CurrentResultsY0);
            }else{
                double d=100.0*okNumber/(okNumber+wrongNumber);
                str=""+(d+0.05);
                if (str.length()-str.indexOf(".")>1)
                    str=str.substring(0,str.indexOf(".")+2);
                g2.drawString(str+"%",p3CurrentResultsX0,p3CurrentResultsY0);
            }
        }

        if (historyInfo!=null){
            g2.drawString(p4Title,p4TitleX0,p4TitleY0);

            g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.BOLD,30));
            str=historyInfo.trainningCategory+" ("+historyInfo.trainningTitle+")";
            int strLen=g.getFontMetrics().stringWidth(str);
            g2.drawString(str,512-strLen/2,60);

            g2.drawString("",p1CurrentResultsX0-10,baseY0-60);

            g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,20));
            //g2.drawString("",p1CurrentResultsX0-10,baseY0-60);
            g2.drawString("当前训练准确率",p1CurrentResultsX0-30,baseY0);
            //g2.drawString("",p1AvgResultsX0-10,baseY0-60);
            g2.drawString("历史平均准确率",p1AvgResultsX0-40,baseY0);

            g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,26));

            okNumber=0;                
            wrongNumber=0;                
            for (int i=0; i<exerciseTopics.size(); i++){
                tmpTopic=exerciseTopics.elementAt(i);

                if (tmpTopic.actionResult==ElfiiCommonConstant.React_Ok){
                    okNumber++;
                }else{
                    wrongNumber++;
                }
            }
            str="0.0";
            if (okNumber>0){
                double d=100.0*okNumber/(okNumber+wrongNumber);
                str=""+(d+0.05);
                if (str.length()-str.indexOf(".")>1)
                    str=str.substring(0,str.indexOf(".")+2);
            }
            g2.drawString(str+"%",p4CurrentResultsX0,p4CurrentResultsY0);

            g2.drawString(historyInfo.allAvgSection_1,p1AvgResultsX0,p1AvgResultsY0);
            g2.drawString(historyInfo.allAvgSection_2,p2AvgResultsX0,p2AvgResultsY0);
            g2.drawString(historyInfo.allAvgSection_3,p3AvgResultsX0,p3AvgResultsY0);
            g2.drawString(historyInfo.allAvg  ,p4AvgResultsX0,p4AvgResultsY0);

            g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,26));
            strLen=g.getFontMetrics().stringWidth(historyInfo.infoStr);
            g2.drawString(historyInfo.infoStr,512-strLen/2,p4TitleY0+50);
        }
    }
    

	public static class FeedBackType{
		public static final int RIGHT = 0;
		public static final int WRONG = 1;
		public static final int TIMEOUT = 2;
		public static final int CLICK = 3;
		public static final int WARNING = 4;
	}
	
	public static String rightMusic=null;
	public static String wrongMusic=null;
	public static String timeoutMusic=null;
	public static String clickMusic=null;
	public static String warningMusic=null; 
	
	public static String currentMusic=null;
	
//	public static AudioClip rightClip=null;
//	public static AudioClip wrongClip=null;
//	public static AudioClip timeoutClip=null;
//	public static AudioClip clickClip=null;
//	public static AudioClip warningClip=null; 
//	
//	public static AudioClip currentClip=null;
	
	public static void initFeedbackAudio(){
		try {
			 File f=new File(".") ; // . 表示当前目录
	         String path=f.getCanonicalPath();
	            
	         URL url= new URL("file:"+path+"/") ;
			
	        rightMusic = "resource-common/sound/feedback/right.wav";   
	        
	        wrongMusic = "resource-common/sound/feedback/wrong.wav";   
	        
	        timeoutMusic = "resource-common/sound/feedback/timeout.wav";   
	        
	        clickMusic = "resource-common/sound/feedback/click.wav"; 
	        
	        warningMusic = "resource-common/sound/feedback/warning.wav";    
	        
//			rightClip = Applet.newAudioClip(new URL(url,"resource-common/sound/feedback/right.wav"));
//			wrongClip = Applet.newAudioClip(new URL(url,"resource-common/sound/feedback/wrong.wav"));
//			timeoutClip = Applet.newAudioClip(new URL(url,"resource-common/sound/feedback/timeout.wav"));
//			clickClip = Applet.newAudioClip(new URL(url,"resource-common/sound/feedback/click.wav"));
//			warningClip = Applet.newAudioClip(new URL(url,"resource-common/sound/feedback/warning.wav"));
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
    
    /**
     * @param type
     */
    public static void playFeedbackAudio(int type){

//    	if(currentClip!=null){
//    		currentClip.stop();
//    		try {
//				Thread.sleep(2);
//			} catch (InterruptedException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//    	}
//
//    	
//    	
//    	switch(type){
//    	case FeedBackType.RIGHT:
//    		currentClip = rightClip;
//    		break;
//    	case FeedBackType.WRONG:
//    		currentClip = wrongClip;
//    		break;
//    	case FeedBackType.TIMEOUT:
//    		currentClip = timeoutClip;
//    		break;
//    	case FeedBackType.CLICK:
//    		currentClip = clickClip;
//    		break;
//    	case FeedBackType.WARNING:
//    		currentClip = warningClip;
//    		break;
//    	default:
//    		return;
//    	}
//    	
//    	if(currentClip!=null){
//    		currentClip.play();
//    	}
    	
//    	if(currentMusic!=null){
//    		AudioPlayer.player.stop();
//    	}

    	if(!ElfiiCommonConfigUtil.isAudioEffectOn){
    		return;
    	}
    	
    	
    	switch(type){
    	case FeedBackType.RIGHT:
    		currentMusic = rightMusic;
    		break;
    	case FeedBackType.WRONG:
    		currentMusic = wrongMusic;
    		break;
    	case FeedBackType.TIMEOUT:
    		currentMusic = timeoutMusic;
    		break;
    	case FeedBackType.CLICK:
    		currentMusic = clickMusic;
    		break;
    	case FeedBackType.WARNING:
    		currentMusic = warningMusic;
    		break;
    	default:
    		return;
    	}
    	
    	if(currentMusic!=null){
    		try {
    	        InputStream music = new FileInputStream(currentMusic);   
    	        AudioStream play_music = new AudioStream(music);  
    	        AudioPlayer.player.start(play_music);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    	}
    }

}

